import cv2
image = cv2.imread('hat.png',cv2.IMREAD_GRAYSCALE)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(3,3))
gradient1 = cv2.morphologyEx(image,cv2.MORPH_ERODE,kernel)
gradient2 = cv2.morphologyEx(image,cv2.MORPH_DILATE,kernel)
gradient3 = cv2.morphologyEx(image,cv2.MORPH_OPEN,kernel)
gradient4 = cv2.morphologyEx(image,cv2.MORPH_CLOSE,kernel)
gradient5 = cv2.morphologyEx(image,cv2.MORPH_GRADIENT,kernel)
gradient6 = cv2.morphologyEx(image,cv2.MORPH_TOPHAT,kernel)
gradient7 = cv2.morphologyEx(image,cv2.MORPH_BLACKHAT,kernel)
cv2.imshow("Input",image)
cv2.imshow("gradient1",gradient1)
cv2.imshow("gradient2",gradient2)
cv2.imshow("gradient3",gradient3)
cv2.imshow("gradient4",gradient4)
cv2.imshow("gradient5",gradient5)
cv2.imshow("gradient6",gradient6)
cv2.imshow("gradient7",gradient7)
cv2.waitKey()
cv2.destroyAllWindows()
